package com.tbit.main.api;

import cn.hutool.core.bean.BeanUtil;
import com.tbit.common.entity.pojo.dto.AddFaultDTO;
import com.tbit.common.entity.view.Result;
import com.tbit.main.util.ObjectUtil;
import com.tbit.main.constant.MachineFaultLogConstant;
import com.tbit.main.constant.MachineStateConstant;
import com.tbit.main.constant.WorkOrderConstant;
import com.tbit.main.pojo.*;
import com.tbit.main.service.*;
import com.tbit.main.util.Assert;
import com.tbit.main.util.DateTimeUtil;
import com.tbit.main.util.LogUtil;
import com.tbit.main.util.OrderUtil;
import com.tbit.maintain.api.AddFaultApi;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;

/**
 * 上报故障实现类
 * @author <a href="mailto:liu.haoxiang@tbit.com.cn">BUGXiang</a>
 * @version 1.0
 * @since 2025-5-20
 */
@Slf4j
@RestController
public class AddFaultApiImpl implements AddFaultApi {

    @Resource
    private MachineFaultService machineFaultService;

    /**
     * 添加故障
     * @param dto 入参
     * @return Result
     */
    @Override
    public Result<Object> addFault(AddFaultDTO dto) {
        AccountUser accountUserToken = new AccountUser();
        MachineFault machineFault = new MachineFault();
        BeanUtil.copyProperties(dto, accountUserToken);
        BeanUtil.copyProperties(dto, machineFault);
        accountUserToken.setAgents(new ArrayList<>(Collections.singletonList(new Agent(dto.getAccountId(), null, null))));
        machineFaultService.addMachineFault(machineFault, accountUserToken);
        return Result.success();
    }
}
